/**
 * @author rxliuli
 */
(function () {
    const FORWARD_DATA_NAME = 'FORWARD_DATA_NAME'

    /**
     * 跳转到某个视图
     * @param {String} view 跳转到视图页面路径
     * @param {Object} [params={}] 参数对象
     * @returns {String} 使用 common-forward 跳转的全路径
     */
    function forward(view, params = {}) {
        sessionStorage.setItem(FORWARD_DATA_NAME, JSON.stringify(params))
        return location.href = `/common/forward?pagePath=${view.startsWith('/') ? view.substring(1) : view}`
    }

    /**
     * 获取到 url 携带的 json 数据
     *
     * @returns {Object} json 数据
     */
    forward.getData = () => {
        return JSON.parse(sessionStorage.getItem(FORWARD_DATA_NAME))
    }

    window.forward = forward
})()